<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>循环练习(loop practice)</title>
  <style>
    table {
      border-collapse: collapse;
    }
    td {
      color: saddlebrown;
      font-size: 18px;
      padding: 10px;
      border: 1px solid #000;
    }
  </style>
</head>
<body>
  
  <script>

    // 1. 打印 1~100 之间所有能被 3 整除的数
    document.write("<h3>1. 打印 1~100 之间所有能被 3 整除的数</h3>")
    for (let i = 1; i <= 100; i++) {
      if (i % 3 === 0) {
        document.write(i);
      }
    }

    // 2. 在屏幕呈现爱心形状
    document.write("<h3>2. 在屏幕呈现爱心形状</h3>")
    for (let i = 1; i <= 10; i++) {
      document.write("<div>");
      for (let j = 1; j <= 5 - i; j++) {
        document.write("❤");
      }
      document.write("</div>");

      if (i >= 6) {
        document.write("<div>");
        for (let j = 6; j <= i + 1; j++) {
          if (i + 1 >= 10) break
          document.write("❤");
        }
        document.write("</div>");
      }
    }

    // 3. 在屏幕呈现爱心形状图案
    document.write("<h3>3. 在屏幕呈现爱心形状图案</h3>")
    for (var i = 0; i < 5; i++) {
      document.write("<div>")
      for (var m = 0; m < 6; m++) {
        document.write("❤ ")
      }
      document.write("</div>")
    }

    // 4. 乘法口诀表 - 表格
    document.write("<h3>4. 乘法口诀表 - 表格</h3>")
    document.write("<table>")
    for (let i = 1; i < 9; i++) {
      document.write("<tr>")
      for (let j = 1; j <= i; j++) {
        document.write('<td>' + j + " * " + i + " = " + i * j + " &nbsp;</td>")
      }
      document.write("</tr>")
    }
    document.write("</table>")

    // 5. 随机生成10个1-100之间的随机数
    document.write("<h3>5. 随机生成10个1-100之间的随机数</h3>")
    for (let i = 0; i < 10; i++) {
      document.write(Math.floor(Math.random() * 100) + 1 + " ")
    }

  </script>
  
</body>
</html>